{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "01194a38",
   "metadata": {},
   "outputs": [],
   "source": [
    "mxd名字 = \"265+240_雪层杜鹃、髯花杜鹃灌丛+硬叶柳灌丛\"\n",
    "图斑shp名字 = \"416_雪层杜鹃、髯花杜鹃灌丛jia硬叶柳灌丛_苔原带\"\n",
    "#随便挑一个温度带的地域mxd,图斑shp复制过来就行\n",
    "\n",
    "群系路径 = r\"E:\\oo\\area\\265+240_雪层杜鹃、髯花杜鹃灌丛+硬叶柳灌丛\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d995c5fc",
   "metadata": {},
   "source": [
    "# 更新群系前关掉gis运行下面的部分把群系重命名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0ecc2fe4",
   "metadata": {},
   "outputs": [],
   "source": [
    "savecode,savename = mxd名字.split(\"_\")[:2]\n",
    "polycode,polyname = 图斑shp名字.split(\"_\")[:2]\n",
    "\n",
    "def rep(st):\n",
    "    st = st.replace(savecode,\"scode\")\n",
    "    st = st.replace(savename,\"sname\")\n",
    "    st = st.replace(polycode,\"pcode\")\n",
    "    st = st.replace(polyname,\"pname\")\n",
    "    return st\n",
    "\n",
    "import os\n",
    "for root,dirs,files in os.walk(群系路径,topdown=False): \n",
    "    for file in files:\n",
    "        filename_path=os.path.join(root,file)\n",
    "        new_filename = rep(file)\n",
    "        new_filename_path=os.path.join(root,new_filename)\n",
    "        os.rename(filename_path,new_filename_path)\n",
    "    for dir in dirs:\n",
    "        dir_path=os.path.join(root,dir)\n",
    "        new_dir = rep(dir)\n",
    "        new_dir_path=os.path.join(root,new_dir)\n",
    "        os.rename(dir_path,new_dir_path)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c97ec4c1",
   "metadata": {},
   "source": [
    "# 更新群系后关掉gis运行下面的部分恢复命名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8425dad3",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def rep(st):\n",
    "    st = st.replace(\"scode\",savecode)\n",
    "    st = st.replace(\"sname\",savename)\n",
    "    st = st.replace(\"pcode\",polycode)\n",
    "    st = st.replace(\"pname\",polyname)\n",
    "    return st\n",
    "\n",
    "import os\n",
    "for root,dirs,files in os.walk(群系路径,topdown=False): \n",
    "    for file in files:\n",
    "        filename_path=os.path.join(root,file)\n",
    "        new_filename = rep(file)\n",
    "        new_filename_path=os.path.join(root,new_filename)\n",
    "        os.rename(filename_path,new_filename_path)\n",
    "    for dir in dirs:\n",
    "        dir_path=os.path.join(root,dir)\n",
    "        new_dir = rep(dir)\n",
    "        new_dir_path=os.path.join(root,new_dir)\n",
    "        os.rename(dir_path,new_dir_path)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
